package domain;

public class IP implements Conexion{

	private int fstOct;
	private int sndOct;
	private int trdOct;
	private int fthOct;

	public IP(int fstOct, int sndOct, int trdOct, int fthOct) {
		super();
		this.fstOct = fstOct;
		this.sndOct = sndOct;
		this.trdOct = trdOct;
		this.fthOct = fthOct;
	}

	@Override
	public boolean estaEnRango(Conexion c1, Conexion c2) {
		return this.esMayorOIgual((IP)c1) && this.esMenorOIgual((IP)c2);
	}
	
	private boolean esMenorOIgual(IP ipFinal) {
		return !esMayorOIgual(ipFinal) || this.equals(ipFinal);
	}

	private boolean esMayorOIgual(IP ipInicial) {
		if (this.getFstOct() <= ipInicial.getFstOct()) {
			if (this.getSndOct() <= ipInicial.getSndOct()) {
				if (this.getTrdOct() <= ipInicial.getTrdOct()) {
					if (this.getFthOct() < ipInicial.getFthOct()) {
						return false;
					}
				}
			}
		}
		return true;
	}

	public int getFstOct() {
		return fstOct;
	}

	public void setFstOct(int fstOct) {
		this.fstOct = fstOct;
	}

	public int getSndOct() {
		return sndOct;
	}

	public void setSndOct(int sndOct) {
		this.sndOct = sndOct;
	}

	public int getTrdOct() {
		return trdOct;
	}

	public void setTrdOct(int trdOct) {
		this.trdOct = trdOct;
	}

	public int getFthOct() {
		return fthOct;
	}

	public void setFthOct(int fthOct) {
		this.fthOct = fthOct;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + fstOct;
		result = prime * result + fthOct;
		result = prime * result + sndOct;
		result = prime * result + trdOct;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		IP other = (IP) obj;
		if (fstOct != other.fstOct)
			return false;
		if (fthOct != other.fthOct)
			return false;
		if (sndOct != other.sndOct)
			return false;
		if (trdOct != other.trdOct)
			return false;
		return true;
	}
}
